package map_struct.bean_mapper;

import map_struct.bo.CarBO;
import map_struct.po.AttributePO;
import map_struct.po.CarPO;
import map_struct.vo.CarDiffNameVO;
import map_struct.vo.CarVO;
import map_struct.vo.CarWithTimeVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * Description: bean映射类
 *
 * @author code-worker
 * @date 2021/10/02 23:24
 */
@Mapper
public interface BeanCovertBasic {
    BeanCovertBasic INSTANCE = Mappers.getMapper(BeanCovertBasic.class);

    /**
     * task: 映射类(CarPO ==> CarVO)
     * @author code-worker
     * @date 2021/10/2 23:30
     * @param source CarPO
     * @return mapstruct_demo.vo.CarVO
     */
    CarVO carPoToCarVo(CarPO source);

    /**
     * task: 映射类(CarPO ==> CarDiffNameVo
     * @author code-worker
     * @date 2021/10/2 23:39
     * @param source CarPO
     * @return map_struct_demo.vo.CarDiffNameVO
     */
    @Mapping(source = "id", target = "carId")
    @Mapping(source = "brand", target = "carName")
    CarDiffNameVO carPoToCarDiffNameVo(CarPO source);

    /**
     * task: 映射类(List<CarPO> ==> List<CarVO>)
     * @author code-worker
     * @date 2021/10/2 23:47
     * @param source List<CarPO>
     * @return java.util.List<map_struct_demo.vo.CarVO>
     */
    List<CarVO> carPosToCarVos(List<CarPO> source);

    /**
     * task: 映射类(CarPO ==> CarWithTimeVO)
     * @author code-worker
     * @date 2021/10/2 23:57
     * @param source CarPO
     * @return map_struct_demo.vo.CarWithTimeVO
     */
    @Mappings({
            @Mapping(source = "brand", target = "carName"),
            @Mapping(target = "createTimeWithFormat", expression = "java(source.getCreateTime().format(java.time.format.DateTimeFormatter.BASIC_ISO_DATE))")
    })
    CarWithTimeVO carPoToCarWithTimeVo(CarPO source);

    /**
     * task: 映射类(CarPO+AttributePO ==> CarBo)
     * @author code-worker
     * @date 2021/10/3 0:18
     * @param source1 CarPO
     * @param source2 AttributePo
     * @return map_struct_demo.bo.CarBO
     */
    @Mapping(source = "source1.brand", target = "carName")
    CarBO carPoAndAttributePoToCarBo(CarPO source1, AttributePO source2);
}
